package com.xbongbong.saas.factory.publicrule;

import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.pro.constant.I18nStringConstant;
import com.xbongbong.pro.enums.errorcodes.SystemErrorCodeEnum;
import com.xbongbong.saas.enums.CustomerRuleEnum;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 功能类工厂类
 * @author : chy
 * @date 创建时间：2018-5-16 下午6:55:18
 * @version v3.22
 */
@Component
public class CheckRuleFactory {

	@Resource
	private CheckRuleNoCommunicate checkRuleNoCommunicate;
	@Resource
	private CheckRuleNoOpportunity checkRuleNoOpportunity;
	@Resource
	private CheckRuleNoContract checkRuleNoContract;
	@Resource
	private CheckRuleMaxCustomerNum checkRuleMaxCustomerNum;
	@Resource
	private CheckRulePrePrincipal checkRulePrePrincipal;
	@Resource
	private CheckRuleGainRate checkRuleGainRate;

	public ICheckRule checkRuleFactory(Integer ruleType) throws XbbException {

		CustomerRuleEnum customerRuleEnum = CustomerRuleEnum.getByCode(ruleType);

		switch (customerRuleEnum) {
			case NO_CUSTOMER_COMMUNICATE_RULE:
				return checkRuleNoCommunicate;
			case NO_OPPORTUNITY_RULE:
				return checkRuleNoOpportunity;
			case NO_CONTRACT_RULE:
				return checkRuleNoContract;
			case MAX_CUSTOMER_NUM_RULE:
				return checkRuleMaxCustomerNum;
			case PRE_PRINCIPAL_RULE:
				return checkRulePrePrincipal;
			case GAIN_RATE_RULE:
				return checkRuleGainRate;
			default:
				throw new XbbException(SystemErrorCodeEnum.API_ERROR_100028, I18nStringConstant.RULE_TYPE_ERROR);
		}
	}
}
